# -*- coding:utf-8 -*-

import sys
sys.path.append('/workspace/dynamic-portfolio-optimizer')

import time
import numpy as np

from src.algorithms.nsga2 import DynamicNSGA2

def benchmark_nsga2():
    """NSGA-II性能基准测试"""
    nsga2 = DynamicNSGA2(population_size=100, generations=50)
    
    # 生成测试数据
    n_assets = 10
    returns = np.random.normal(0.08, 0.05, n_assets)
    cov_matrix = np.random.rand(n_assets, n_assets)
    cov_matrix = np.dot(cov_matrix, cov_matrix.T)
    esg_scores = np.random.uniform(50, 90, n_assets)
    
    constraints = {
        'max_single_weight': 0.3,
        'min_cash_ratio': 0.05
    }
    
    start_time = time.time()
    population = nsga2.optimize(returns, cov_matrix, esg_scores, constraints)
    end_time = time.time()
    
    print(f"⏱️  优化时间: {end_time - start_time:.2f}秒")
    print(f"🎯 Pareto解数量: {len([ind for ind in population if ind.rank == 0])}")

if __name__ == "__main__":
    benchmark_nsga2()
